from django.db import models

# Create your models here.
class BookInfo(models.Model):
    # 创建字段，字段类型...
    #属性名
    name = models.CharField(max_length=10,unique=True,verbose_name='书名')
    # 发布日期
    pub_date=models.DateField(null=True)
    #阅读量
    readcount =models.IntegerField(default=0)

    class Meta:
        #改表名 改的是数据库中的表名
        db_table='bookinfo'
        #
        verbose_name_plural='书名'
    def __str__(self):
        return  self.name
# 准备人物列表信息的模型类
class PeopleInfo(models.Model):
    GENDER_CHOICES = (
        (0, 'male'),
        (1, 'female')
    )
    name = models.CharField(max_length=20, verbose_name='名称')
    gender = models.SmallIntegerField(choices=GENDER_CHOICES, default=0, verbose_name='性别')
    description = models.CharField(max_length=200, null=True, verbose_name='描述信息')

    book = models.ForeignKey(BookInfo, on_delete=models.CASCADE, verbose_name='图书')  # 外键
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'peopleinfo'
        verbose_name_plural = '人物信息'

    def __str__(self):
        return self.name